package com.gec.it;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.File;

@WebListener
public class Listener implements ServletContextListener, HttpSessionListener, HttpSessionAttributeListener {

    @Override
    public void contextInitialized(ServletContextEvent sce) {
        ServletContext application= sce.getServletContext();
        //定位保存路径
        String imgpath=application.getInitParameter("doc_imgs");//读配置
        String webapps=new File(application.getRealPath("/")).getParent();//获得tomcat的webapps目录路径
        //自动创建文件夹
        File dir=new File(webapps+imgpath);
        if(!dir.exists())
            dir.mkdirs();
        application.setAttribute("dir_docimg",webapps+"/"+imgpath);
    }

    @Override
    public void contextDestroyed(ServletContextEvent sce) {

    }

    @Override
    public void sessionCreated(HttpSessionEvent se) {

    }

    @Override
    public void sessionDestroyed(HttpSessionEvent se) {

    }

    @Override
    public void attributeAdded(HttpSessionBindingEvent event) {

    }

    @Override
    public void attributeRemoved(HttpSessionBindingEvent event) {

    }

    @Override
    public void attributeReplaced(HttpSessionBindingEvent event) {

    }
}
